﻿using System;
using System.IO;
using System.Text;

namespace TfsGiggle.Core.IntegrationTest
{
    class MockItem : IItem
    {
        private int _id;
        private string _contents;
        private string _name;

        internal MockItem(int id, string name, string contents)
        {
            _id = id;
            _name = name;
            _contents = contents;
        }

        public int ChangesetId
        {
            get { return _id; }
        }

        public Stream DownloadFile()
        {
            // MemoryStream does not seem to work well with Lucene
            var name = Path.GetTempFileName();
            File.WriteAllText(name, _contents, UTF8Encoding.UTF8);
            return new StreamReader(name, UTF8Encoding.UTF8, true).BaseStream;
        }

        public int Encoding
        {
            get { return UTF32Encoding.UTF8.WindowsCodePage; }
        }

        public string ServerItem
        {
            get { return _name; }
        }

        public DateTime CheckinDate
        {
            get { return DateTime.Now; }
        }

        public IVersionControlServer VersionControlServer
        {
            get { return MockVersionControlServer.Instance; }
        }
    }
}